home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / colors.cpp < prev    next >
C/C++ Source or Header  |  1995-01-20  |  5KB  |  196 lines

  1. #include <stdlib.h>
  2. #include "colors.h"
  3. #include <process.h>
  4. #include <iostream.h>
  5.  
  6.  
  7. #define CO_16 = 15;   // 16 color mode
  8.  
  9. ColorSet* pColorSet;
  10. ScreenSet* pScreenSet;
  11.  
  12.  
  13. ColorSet::ColorSet()
  14.     {
  15.     color_set_number = 1;
  16.     loadColorSet(0);
  17.     }
  18. //////////////////////////
  19. void ColorSet::loadColorSet(int number)
  20.     {
  21.     if(color_set_number == number)    // Already loaded
  22.         return;
  23.     color_set_number = number;
  24.     char* colorSetFileName = "colors.set";
  25.     FILE* colorFP;
  26.     if((colorFP = fopen(colorSetFileName, "r")) == NULL)       // Can not open
  27.         exit(1);
  28.     int count = 0;
  29.     char s[30];
  30.     while(count < number)
  31.         {
  32.     if(fgets(s, 29, colorFP) == NULL)
  33.         exit(1);
  34.         if(s[0] == '@')
  35.             count++;
  36.         }
  37.  
  38.     fgets(s, 29, colorFP);
  39.     s[2] = '\0';
  40.     colors.HILITE_COLOR = atoi(s);
  41.     fgets(s, 29, colorFP);
  42.     s[2] = '\0';
  43.     colors.BAK_COLOR = atoi(s);
  44.     fgets(s, 29, colorFP);
  45.     s[2] = '\0';
  46.     colors.FILL_COLOR = atoi(s);
  47.     fgets(s, 29, colorFP);
  48.     s[2] = '\0';
  49.     colors.ATTR_COLOR = atoi(s);
  50.     fgets(s, 29, colorFP);
  51.     s[2] = '\0';
  52.     colors.SHADOW_COLOR = atoi(s);
  53.     fgets(s, 29, colorFP);
  54.     s[2] = '\0';
  55.     colors.HDR_BAK_COLOR = atoi(s);
  56.     fgets(s, 29, colorFP);
  57.     s[2] = '\0';
  58.     colors.HDR_ATTR_COLOR = atoi(s);
  59.     fgets(s, 29, colorFP);
  60.     s[2] = '\0';
  61.     colors.MARK_COLOR = atoi(s);
  62.     fgets(s, 29, colorFP);
  63.     s[2] = '\0';
  64.     colors.MARK_BAK_COLOR = atoi(s);
  65.     fgets(s, 29, colorFP);
  66.     s[2] = '\0';
  67.     colors.BORDER_COLOR1 = atoi(s);
  68.     fgets(s, 29, colorFP);
  69.     s[2] = '\0';
  70.     colors.BORDER_COLOR2 = atoi(s);
  71.     fgets(s, 29, colorFP);
  72.     s[2] = '\0';
  73.     colors.BORDER_COLOR3 = atoi(s);
  74.  
  75.     fclose(colorFP);
  76.     }
  77. ////////////////////////////
  78. // This function initialise system not for all possible modes.
  79. // To use another regime or mode - add corresponding block
  80. ScreenSet::ScreenSet(int gdriver, int gmode)
  81.     {
  82.     icon_types[0] = loc(0, 0);
  83.     icon_types[1] = loc(7, 3);            // TEXT size of icons
  84.     icon_types[2] = loc(3, 1);
  85.     icon_types[3] = loc(15, 5);
  86.  
  87.     int maxX = getmaxx() + 1;
  88.     int maxY = getmaxy() + 1;
  89.  
  90.     cell_height = maxY / 25;
  91.     if(maxX == 640)             // To use system with low resolution add
  92.     log2cell_width = 3;     // corresponding operator.
  93.     else
  94.         log2cell_width = 4;
  95.  
  96.     cell_width  = 1 << log2cell_width;
  97.  
  98.     ICON_PIXELS_1 = loc(cell_width * 7, cell_height * 3);
  99.     ICON_PIXELS_2 = loc(cell_width * 3, cell_height);
  100.     ICON_PIXELS_3 = loc(cell_width * 15, cell_height * 5);
  101.  
  102.     standart_width =   cell_width;  // Char dimentions, not connected with
  103.     standart_height =  cell_width;  // cells. Used as default for screen
  104.     sub_interval    = cell_width + 4;  // output.
  105.  
  106.     g_driver = gdriver; g_mode = gmode;
  107.     }
  108. //////////////////////////
  109. int* ScreenSet::get_cells(rect cur_rect)
  110.     {
  111.     int* cells = new int[25 * 80 + 1];
  112.     int cells_num = 0;
  113.     for(int y = cur_rect.origin.Y; y < cur_rect.corner.Y + 1;
  114.     y += pScreenSet->cell_height)
  115.     for(int x = cur_rect.origin.X; x < cur_rect.corner.X + 1;
  116.         x += pScreenSet->cell_width)
  117.         {
  118.         cells[cells_num] = y / pScreenSet->cell_height * 80
  119.         + (x >> pScreenSet->log2cell_width);
  120.         cells_num++;
  121.         }
  122.  
  123.     cells[cells_num] = -1;
  124.  
  125.     return cells;
  126.     }
  127. //////////////////////////
  128. int init_KNOW_HOW(int gdriver, int macros)
  129.     {
  130.     int gmode;
  131.     if(gdriver == -1)                  // Ask for the monitor type
  132.         {
  133.     cout << "\n\n    KNOW-HOW Object Oriented Graphics Tools Line\n\n";
  134.         cout << "    (C) Stepan Vartanov, 1992 - 1994.\n";
  135.     cout << " \n";
  136.         cout << "███████████████████████████████\n";
  137.         cout << "████ VGAMED, EGAHI....1 ███████\n";
  138.         cout << "████ VGAHI............2 ███████\n";
  139.         cout << "███████████████████████████████\n";
  140.         cout << " Input monitor mode: ";
  141.         int a;
  142.         cin >> a;
  143.         switch(a)
  144.         {
  145.         case 2: gdriver = VGA; gmode=VGAHI; break;
  146.         default: gdriver = EGA; gmode=EGAHI; break;
  147.             }
  148.         }
  149.     else
  150.         switch(gdriver)
  151.         {
  152.         case EGA: gmode = EGAHI; break;
  153.             case VGA: gmode = VGAHI; break;
  154.             default: break;
  155.             }
  156.     int errorcode;
  157.     initgraph(&gdriver, &gmode, "");
  158.     errorcode = graphresult();
  159.     if (errorcode != grOk)  /* An error occurred */
  160.         return 0;
  161.     global_init();   // initialize global with 0
  162.     if(macros)
  163.         init_macros();
  164.     pScreenSet = new ScreenSet(gdriver, gmode);
  165.     pColorSet = new ColorSet();
  166.  
  167.     mouseReset();  // mouse init
  168.     return 1;
  169.     }
  170. //////////////////////
  171. void close_KNOW_HOW()
  172.     {
  173.     delete pScreenSet;
  174.     delete pColorSet;
  175.     global_remove();
  176.  
  177.     while(macros_used > 0)             // if script will terminate the program
  178.     {                               // and stack is not empty
  179.     mac_status mac = macros_pop();
  180.     delete mac.file;
  181.     }
  182.     delete scriptFileName;
  183.  
  184.     fcloseall();
  185.     }
  186. //////////////////////
  187. /*
  188. void main()
  189.     {
  190.     if(!init_KNOW_HOW())
  191.         return;
  192.     pColorSet->loadColorSet(2);
  193.     close_KNOW_HOW();
  194.     closegraph();
  195.     }
  196. */